import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 引入node api 可配合@types/node提供类型提示
import path from 'node:path'
import xwPx2vw from './vite-plugins/vite-plugin-xw-px2vw'
import vueJsx from '@vitejs/plugin-vue-jsx'
// element-plus按需导入，免引入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(), vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    open: true
  },
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src'),
      '@components': path.join(__dirname, 'src/components'),
      "@layout": path.join(__dirname, 'src/layout'),
      "@views": path.join(__dirname, 'src/views')
    }
  },
  css: {
    // 添加全局css预样式
    
    preprocessorOptions: {
      scss: {
        additionalData: `
          @import "@/styles/bem.scss";
          @import "@/styles/layout.scss";
        `
      }
    },
    postcss: {
      plugins: [xwPx2vw()]
    }
  }
})
